const globalIp = getApp().globalData.userIp
Page({

  /**
   * 页面的初始数据
   */
  data: {
    value: '',
    title: '',
    info: '',
    pageIndex: 1,
    projectList: [],
    concatList:[]
  },

  getInputValue: function(e){
    this.setData({
      info: e.detail.value
    })
  },
  selectData: function(){
    this.setData({
      pageIndex: 1
    })
    this.getProjectTwo();
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) { 
    if (options && options.Levels) {
      this.setData({
        value: options.Levels
      })
      if (options.Levels == '2') {
        wx.setNavigationBarTitle({
          title: '一月内下单',
        })  
        this.setData({
          title: '一月内下单'
        })
      } else if (options.Levels == '3') {
        wx.setNavigationBarTitle({
          title: '三月内下单',
        })
        this.setData({
          title: '三月内下单'
        })
      } else if (options.Levels == '4') {
        wx.setNavigationBarTitle({
          title: '半年内下单',
        })
        this.setData({
          title: '半年内下单'
        })
      } else if (options.Levels == '5') {
        wx.setNavigationBarTitle({
          title: '一年内下单',
        })
        this.setData({
          title: '一年内下单'
        })
      } else if (options.Levels == '6') {
        wx.setNavigationBarTitle({
          title: '一年以外未下单',
        })
        this.setData({
          title: '一年以外未下单'
        })
      }
      this.getProjectTwo();
    }
  },

  getProjectTwo() {
    let that = this;
    wx.showLoading({
      title: '加载中',
      mask: true
    })
    wx.request({
      url: globalIp + 'home/ocrd/getCardActive',
      data: {
        value: that.data.value || '',
        userName: that.data.info || '',
        pageIndex: that.data.pageIndex,
        openId: wx.getStorageSync('userInfo').openid || ''
      },
      header: {
        'content-type': 'application/json'
      },
      method: 'POST',
      success: function(res) {
        if (res.data.jsonObject) {
          var data = res.data.jsonObject.data;
          if (data.length > 1) {
            var arr = [];
            var res = [];
            for (var i in data) {
              arr[i] = [];
              for(var j in data[i]) {
                arr[i].push(data[i][j]);
              }
            }
            if (arr.length > 0) {
              for (var i = 0; i < arr[0].length; ++i) {
                res[i] = [];
                for (var j = 0; j < arr.length; ++j) {
                  res[i][j] = arr[j][i];
                }
              }
              that.setData({
                projectList: res
              })
            }
          } else {
            that.setData({
              pageIndex: that.data.pageIndex - 1
            })
            wx.showToast({
              title: '已到达最后一页~',
            })
          }
        } 
      },
      fail: function(res) {
        wx.showToast({
          title: '请返回上一页面，重新请求',
          icon: 'none',
          duration: 2000,
        })
      },
      complete: function(res) {
        wx.hideLoading()
      }
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  /**
  * 页面下拉刷新事件的处理函数
  */
 onPullDownRefresh(e) {
    // wx.stopPullDownRefresh()
 },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom(e) {
    
  },

  prevPage: function() {
    if (this.data.pageIndex === 1) {
      wx.showToast({
        title: '已经到达第一页~',
      })
    } else {
        this.setData({
          pageIndex: this.data.pageIndex - 1
        })
        this.getProjectTwo()
    }
  },

  nextPage: function() {
    this.setData({
      pageIndex: this.data.pageIndex + 1
    })
    this.getProjectTwo()
  }
  
})